package interfejs;

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import kontroler.VehiclesPanelController;



import viewModel.VehiclesTableModel;


public class VehiclesPanel extends JPanel {
	
	private JTable vehicleTable;
	private AddVehicleFrame addVehicleFrame;
	
	
	

	 public VehiclesPanel(){
		    super(new BorderLayout());
		    
		    vehicleTable = new JTable(new VehiclesTableModel());
		    vehicleTable.setPreferredScrollableViewportSize(new Dimension(vehicleTable.getWidth(), 100));
		    vehicleTable.setFillsViewportHeight(true);
		    vehicleTable.getModel().addTableModelListener(new VehiclesPanelController());
		   
		    JScrollPane scrollPane = new JScrollPane(vehicleTable);
		    add(scrollPane, BorderLayout.CENTER);   
		    
		    JToolBar buttonGroup = new JToolBar();
		    buttonGroup.setFloatable(false);
		    
		    JButton addNewClient = new JButton("Nowy samochod");
		    addNewClient.setActionCommand("NEW_VEHICLE");
		    addNewClient.addActionListener(new VehiclesPanelController());
		    addNewClient.setToolTipText("Kliknij aby przejsc do formularza dodania nowego samochodu");
		    buttonGroup.add(addNewClient);
		    add(buttonGroup, BorderLayout.SOUTH);
		  }
	
	public void setAddVehicleFrame(AddVehicleFrame addVehicleFrame) {
		this.addVehicleFrame = addVehicleFrame;
	}

	public VehiclesTableModel getVehiclesTableModel() {
		return (VehiclesTableModel) vehicleTable.getModel();
	}
	
	public JTable getVehiclesTable() {
		return vehicleTable;
	}

	public AddVehicleFrame getAddVehicleFrame() {
		return addVehicleFrame;
	}
	
}

